<?php
namespace app\admin\controller;
use think\Controller;
class Topup extends Common
{
	public function index(){
		$all = input('get.all');
		 $key = trim(input('get.key','','htmlspecialchars'));
        //显示全部数据
		 if($all == 1){
            $data = db('pay')->select();
        }else{         
		    $data = db('pay')->where('username','like',"%".$key."%")->order('id desc')->paginate(15);
        }
        $this->assign('all',$all);
		$this->assign('data',$data);
		return $this->fetch();
	}

	//删除单条记录(删除数据)
	public function del(){
		$id = input('param.id');
		$del = db('pay')->where('id',$id)->delete();
		if($del > 0){
			$content = '删除充值列表';
        	admin_log($content); 
			$this->success('删除成功','index','',1);
		}else{
			$this->error('删除失败','','',1);
		}
	}
	
	//批量删除(批量删除数据)
	public function deleteall(){
		if(request() -> isAjax()){
			$id=$_POST['id'];
			if(db('pay')->delete($id)){
				$content = '删除充值列表';
        	    admin_log($content); 
				echo json_encode(1);
			}else{
				echo json_encode(2);
			}

		}
	}	
}